package com.cicdi;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

/**
 * JavaFX App
 */
public class App extends Application {
    private static Scene scene;

    static void setRoot(String fxml) throws IOException {
        scene.setRoot(loadFXML(fxml));
    }

    private static Parent loadFXML(String fxml) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
        return fxmlLoader.load();
    }

    public static void main(String[] args) {
        launch();
    }

    @Override
    public void stop() throws Exception {
        super.stop();
        System.exit(0);
    }

    @Override
    public void start(Stage stage) throws IOException {
        scene = new Scene(loadFXML("main"), 1280, 720);
        stage.setScene(scene);
        stage.show();

//        stage.setOnCloseRequest(event -> {
//            //对话框 Alert Alert.AlertType.CONFIRMATION：反问对话框
//            Alert alert2 = new Alert(Alert.AlertType.CONFIRMATION);
//            //设置对话框标题
//            alert2.setTitle("退出");
//            //设置内容
//            alert2.setHeaderText("确定要退出吗");
//            //显示对话框
//            Optional<ButtonType> result = alert2.showAndWait();
//            //如果点击OK
//            result.ifPresent(
//                    r -> {
//                        if (r == ButtonType.OK) {
//                            stage.close();
//                            System.exit(0);
//                        } else {
//                            event.consume();
//                        }
//                    }
//            );
//        });
    }

}